package org.jason.common.rabbitmq;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {

    @Bean
    public MessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        factory.setMessageConverter(new Jackson2JsonMessageConverter());
        return factory;
    }

    //声明投稿队列
    @Bean
    public Queue contributeQueue() {
        return new Queue("contribute.queue");
    }

    //声明评论队列
    @Bean
    public Queue commentQueue() {
        return new Queue("comment.queue");
    }

    //声明文章互动队列
    @Bean
    public Queue articleBehaviorQueue() {
        return new Queue("article.behavior.queue");
    }

    //声明文章取消互动队列
    @Bean
    public Queue articleUnBehaviorQueue() {
        return new Queue("article.cancel.queue");
    }

    //声明用户头像修改队列
    @Bean
    public Queue userAvatarQueue() {
        return new Queue("user.avatar.queue");
    }

}
